package com.cms.admin.action.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import net.sf.json.JSONObject;

import com.cms.admin.action.BaseAction;


import com.cms.admin.model.City;
import com.cms.admin.model.FuncList;
import com.cms.admin.model.UserList;
import com.cms.admin.model.UserRole;
import com.cms.admin.service.common.FuncListService;
import com.cms.admin.service.privilege.CityService;
import com.cms.admin.util.Constants;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

public class IndexAction extends BaseAction {

    private Map request;
    private Map session;
    private Map application;


    private FuncListService funcListService;

    private CityService cityService;

    private ArrayList<City> orgList;

    private ArrayList<City> subOrgList;

    private Map<FuncList, List<FuncList>> menuMap = new TreeMap<FuncList, List<FuncList>>();

    private UserList user = null;

    private UserRole role = null;

    List<FuncList> tree = null;

    public List<FuncList> getTree() {
        return tree;
    }

    public void setTree(List<FuncList> tree) {
        this.tree = tree;
    }

    public Map<FuncList, List<FuncList>> getMenuMap() {
        return menuMap;
    }


    public void setMenuMap(Map<FuncList, List<FuncList>> menuMap) {
        this.menuMap = menuMap;
    }


    public IndexAction() {
        HttpServletRequest servletRequest = ServletActionContext.getRequest();
        request = (Map) ActionContext.getContext().get("request");
        session = ActionContext.getContext().getSession();
        application = ActionContext.getContext().getApplication();

        user = (UserList) servletRequest.getSession().getAttribute(Constants.USER_OBJECT);
        role = (UserRole) session.get(Constants.ROLE_OBJECT);

    }


    public String getHeader() {


        return "getHeader";
    }

    public String getMenus() {

        tree = funcListService.getAllMenu();

        return "getMenus";
    }


    public String getFirstPageData() {

        LOG.info("Start ArticleAction process,method is getFirstPageData");


        String res = null;
        JSONObject o = new JSONObject();

        o.put("content", res);
        return "success";


    }


    public FuncListService getFuncListService() {
        return funcListService;
    }


    public void setFuncListService(FuncListService funcListService) {
        this.funcListService = funcListService;
    }


    public CityService getCityService() {
        return cityService;
    }


    public void setCityService(CityService cityService) {
        this.cityService = cityService;
    }


    public ArrayList<City> getOrgList() {
        return orgList;
    }


    public void setOrgList(ArrayList<City> orgList) {
        this.orgList = orgList;
    }


    public ArrayList<City> getSubOrgList() {
        return subOrgList;
    }


    public void setSubOrgList(ArrayList<City> subOrgList) {
        this.subOrgList = subOrgList;
    }


}
